package com.pdweb.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pdweb.dao.TurnosDao;
import com.pdweb.vo.Turnos;

/**
 * Servlet implementation class TurnosAdicionaServlet
 */
@WebServlet("/TurnosAdicionaServlet")
public class TurnosAdicionaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TurnosAdicionaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doService(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		doService(request, response);

	}
	
	protected void doService(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
	
		try {

			Turnos turno = new Turnos();

			turno.setNomeTurno(request.getParameter("ST_NOME_TURN"));
			turno.setHoraEntrada(request.getParameter("ST_ENTRADA_TURN"));
			turno.setHoraAlmocoSaida(request.getParameter("ST_ALMOCOSAIDA_TURN"));
			turno.setHoraAlmocoRetorno(request.getParameter("ST_ALMOCORETORNO_TURN"));
			turno.setHoraSaida(request.getParameter("ST_SAIDA_TURN"));
			

			TurnosDao turnosDao = new TurnosDao();

			turnosDao.adicionaTurnos(turno);
			
			getServletContext().getRequestDispatcher("/TurnosExibirServlet").forward(request,response);
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
